package com.atguigu.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @author:zhuguanming
 * @date:2021/4/18
 */
public class ListValueVerificationValidator implements ConstraintValidator<ListValueVerification, Integer> {

    Set<Integer> validateDatas = new HashSet<>(16);

    @Override
    public void initialize(ListValueVerification constraintAnnotation) {
        for (int value : constraintAnnotation.values()) {
            validateDatas.add(value);
        }
    }

    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        return validateDatas.contains(integer);
    }
}
